package com.xyz.graph.pojo.gdata;

import java.util.*;
import java.util.Map.Entry;

/**
 * 弃用
 */
public class GraphSchema {
    private List<Map<String, String>> vertexLabels = new ArrayList();
    private List<Map<String, String>> propertyKeys = new ArrayList();
    private List<Map<String, String>> edgeLabels = new ArrayList();
    private List<Map<String, String>> indices = new ArrayList();

    public GraphSchema() {
    }

    public void addVertexLabel(String name) {
        Map<String, String> map = new HashMap();
        map.put("name", name);
        this.vertexLabels.add(map);
    }

    public void addPropertyKey(String name, GraphSchema.PropertyDataType dataType) {
        if (!this.checkPropertyKey(name)) {
            throw new RuntimeException("invalid key name:" + name);
        } else {
            Map<String, String> map = new HashMap();
            map.put("name", name);
            map.put("dataType", dataType.value);
            this.propertyKeys.add(map);
        }
    }

    public void addPropertyKey(String name, GraphSchema.PropertyDataType dataType, GraphSchema.PropertyCardinality cardinality) {
        if (!this.checkPropertyKey(name)) {
            throw new RuntimeException("invalid key name:" + name);
        } else {
            Map<String, String> map = new HashMap();
            map.put("name", name);
            map.put("dataType", dataType.value);
            map.put("cardinality", cardinality.value);
            this.propertyKeys.add(map);
        }
    }

    public void addEdgeLabel(String name) {
        Map<String, String> map = new HashMap();
        map.put("name", name);
        this.edgeLabels.add(map);
    }

    public void addEdgeLabel(String name, GraphSchema.EdgeLabelMultiplicity multiplicity) {
        Map<String, String> map = new HashMap();
        map.put("name", name);
        map.put("multiplicity", multiplicity.value);
        this.edgeLabels.add(map);
    }

    public void addIndex(String name, GraphSchema.IndexType indexType, GraphSchema.IndexElement element, List<String> keys) {
        Map<String, String> map = new HashMap();
        map.put("name", name);
        map.put("indexType", indexType.value);
        map.put("element", element.value);
        map.put("keys", keys.toString());
        this.indices.add(map);
    }

    public void addStaticIndex(String name, GraphSchema.IndexElement element, List<String> keys, String hashKey, int hashNum) {
        Map<String, String> map = new HashMap();
        map.put("name", name);
        map.put("indexType", GraphSchema.IndexType.Static.value);
        map.put("element", element.value);
        map.put("keys", keys.toString());
        map.put("hashKey", hashKey);
        map.put("hashNum", String.valueOf(hashNum));
        this.indices.add(map);
    }

    public String toYamlString() {
        StringBuilder sb = new StringBuilder();
        sb.append(this.format("VertexLabel", this.vertexLabels));
        sb.append(this.format("PropertyKey", this.propertyKeys));
        sb.append(this.format("EdgeLabel", this.edgeLabels));
        sb.append(this.format("Index", this.indices));
        return sb.toString();
    }

    private String format(String name, List<Map<String, String>> list) {
        StringBuilder sb = new StringBuilder();
        sb.append("---\n");
        sb.append("name: ").append(name).append("\n");
        sb.append("fields:").append("\n");
        Iterator var4 = list.iterator();

        while(var4.hasNext()) {
            Map<String, String> map = (Map)var4.next();
            boolean first = true;
            Iterator var7 = map.entrySet().iterator();

            while(var7.hasNext()) {
                Entry<String, String> entry = (Entry)var7.next();
                if (first) {
                    sb.append(" - ").append((String)entry.getKey()).append(": ").append((String)entry.getValue()).append("\n");
                    first = false;
                } else {
                    sb.append("   ").append((String)entry.getKey()).append(": ").append((String)entry.getValue()).append("\n");
                }
            }
        }

        sb.append("\n");
        return sb.toString();
    }

    private boolean checkPropertyKey(String name) {
        return !name.equals("id") && !name.equals("label") && !name.equals("key") && !name.equals("dir") && !name.equals("schema");
    }

    public static enum PropertyDataType {
        String("string"),
        Character("char"),
        Boolean("boolean"),
        Byte("byte"),
        Short("short"),
        Integer("int"),
        Long("long"),
        Float("float"),
        Double("double"),
        Date("date"),
        Geoshape("geoshape"),
        UUID("uuid");

        private String value;

        private PropertyDataType(String value) {
            this.value = value;
        }

        public static GraphSchema.PropertyDataType toEnum(String name) {
            GraphSchema.PropertyDataType[] var1 = values();
            int var2 = var1.length;

            for(int var3 = 0; var3 < var2; ++var3) {
                GraphSchema.PropertyDataType pdt = var1[var3];
                if (name != null && pdt.value.equalsIgnoreCase(name)) {
                    return pdt;
                }
            }

            return String;
        }
    }

    public static enum PropertyCardinality {
        Single("single"),
        List("list"),
        Set("set");

        private String value;

        private PropertyCardinality(String value) {
            this.value = value;
        }

        public static GraphSchema.PropertyCardinality toEnum(String name) throws RuntimeException {
            GraphSchema.PropertyCardinality[] var1 = values();
            int var2 = var1.length;

            for(int var3 = 0; var3 < var2; ++var3) {
                GraphSchema.PropertyCardinality pdt = var1[var3];
                if (name != null && pdt.value.equalsIgnoreCase(name)) {
                    return pdt;
                }
            }

            throw new RuntimeException("Cannot toEnum PropertyCardinality.");
        }
    }

    public static enum EdgeLabelMultiplicity {
        Multi("multi"),
        Simple("simple"),
        Many2One("many2one"),
        One2Many("one2many"),
        One2One("one2one");

        private String value;

        private EdgeLabelMultiplicity(String value) {
            this.value = value;
        }

        public static GraphSchema.EdgeLabelMultiplicity toEnum(String name) {
            GraphSchema.EdgeLabelMultiplicity[] var1 = values();
            int var2 = var1.length;

            for(int var3 = 0; var3 < var2; ++var3) {
                GraphSchema.EdgeLabelMultiplicity pdt = var1[var3];
                if (name != null && pdt.value.equalsIgnoreCase(name)) {
                    return pdt;
                }
            }

            return Multi;
        }
    }

    public static enum IndexElement {
        Vertex("vertex"),
        Edge("edge");

        private String value;

        private IndexElement(String value) {
            this.value = value;
        }
    }

    public static enum IndexType {
        Composite("composite"),
        Composite_Unique("composite_unique"),
        Mixed("mixed"),
        Static("static");

        private String value;

        private IndexType(String value) {
            this.value = value;
        }
    }
}

